<?php
require_once("header.php");
require_once("model/DB.php");
require_once("model/Class.php");

require_once("model/Kid.php");
require_once("model/Daliy.php");
include("function/teacher.login.php");

$r_date = $_GET['year']."-".$_GET['month']."-".$_GET['day'];
$class = Classes::getClassByTeacher($_SESSION['userid']);
$class_id = $class['id'];



$kids = Kid::getKidByClass($class_id);

?>
<script>
$(document).ready(function(){
	$(".save").click(function(){
		var id=$(this).attr("id");
		var class_id = $("#class").val();
		var date = $("#date").val();
		var status = "";
		var lunch ="";
		var siesta ="";
		var perform = "";
		var link = $(this);
		
		$(this).parents().map(function(i){
			if(i==1){
				$(this).children().each(function(o){
					if(o==1){
						status = $(this).find("input").val();
						
					}
					else if(o==2){
						
						lunch = $(this).find("select").val();
					}
					else if(o==3){
						siesta = $(this).find("select").val();
					}
					else if(o==4){
						perform = $(this).find("select").val();
					}
					
				});
			}
		});
		
		$.post(
			"function/addDaliy.php",
			{
				kid:id,status:status,lunch:lunch,siesta:siesta,perform:perform,class_id:class_id,date:date
			},
			function(data){
				if(data=="saved"){
					alert("Record Saved");
					window.location = window.location;
				}
			}
		);
		
		
	});	
	$(".edit").click(function(){
		var id=$(this).attr("id");
		var class_id = $("#class").val();
		var status = "";
		var lunch ="";
		var siesta ="";
		var perform = "";
		$(this).parents().map(function(i){
			if(i==1){
				$(this).children().each(function(o){
					if(o==1){
						status = $(this).find("input").val();
						
					}
					else if(o==2){
						
						lunch = $(this).find("select").val();
					}
					else if(o==3){
						siesta = $(this).find("select").val();
					}
					else if(o==4){
						perform = $(this).find("select").val();
					}
					
				});
			}
		});
		
		$.post(
			"function/addDaliy.php",
			{
				id:id,status:status,lunch:lunch,siesta:siesta,perform:perform,class_id:class_id
			},
			function(data){
				if(data=="editd"){
					alert("Record Edited");
				}
			}
		);
		
		
	});
	
	
});
</script>
<input type="hidden" id="class" value="<?php echo $class_id; ?>">
<input type="hidden" id="date" value="<?php echo $r_date; ?>">
<table id="kid_table" class="tablesorter">
	<thead>
		<tr><td>Kid Name</td><td>Healthy Status</td><td>Lunch</td><td>siesta</td><td>Perform</td><td>Action</td></tr>
	</thead>
	<tbody>
		<?php foreach($kids as $kid):
			  $check_daliy = Daliy::getDaliy($kid['id'],$r_date);
			 if($check_daliy){
				$color = "finish";
			 }
			 else{
				$color = "notyet";
			 }
			  
		?>
			<tr>
				<td class="<?php echo $color; ?>"><?php echo $kid['name']; ?></td>
				<td class="<?php echo $color; ?>"><input type="text" value="<?php echo $check_daliy['status']; ?>"></td>
				<td class="<?php echo $color; ?>"><select><option value="no">No</option><option value="yes" <?php if($check_daliy['lunch']=='yes'):?> selected <?php endif ?>>Yes</option></select></td>
				<td class="<?php echo $color; ?>"><select><option value="no">No</option><option value="yes" <?php if($check_daliy['siesta']=='yes'):?> selected <?php endif ?>>Yes</option></select></td>
				<td class="<?php echo $color; ?>">
					<select>
						<option value="X"  <?php if($check_daliy['perform']=='X'):?> selected <?php endif ?>>Absent</option>
						<option value="O"  <?php if($check_daliy['perform']=='O'):?> selected <?php endif ?>>Outstanding</option>
						<option value="E"  <?php if($check_daliy['perform']=='E'):?> selected <?php endif ?>>Exceeds Expectations</option>
						<option value="A"  <?php if($check_daliy['perform']=='A'):?> selected <?php endif ?>>Acceptable</option>
						<option value="P"  <?php if($check_daliy['perform']=='P'):?> selected <?php endif ?>>Poor</option>
						<option value="D"  <?php if($check_daliy['perform']=='D'):?> selected <?php endif ?>>Dreadful</option>
						<option value="T"  <?php if($check_daliy['perform']=='T'):?> selected <?php endif ?>>Troll</option>
					</select>
				</td>
				<td class="<?php echo $color; ?>"><?php if($check_daliy): ?><a class="edit" id="<?php echo $check_daliy['id']; ?>" href="javascript:void(0)" onclick="">Edit</a><?php else: ?><a class="save" id="<?php echo $kid['id']; ?>" href="javascript:void(0)">Save</a><?php endif ?></td>

			</tr>
		<?php endforeach; ?>
	</tbody>
</table>
<div id="pager" class="pager" style="width:800px;margin-left:5px;margin-top:15px">
					<form>
						<img class="first" src="images/first.png"/>
						<img class="prev" src="images/prev.png"/>
						<input class="pagedisplay" type="text"/>
						<img class="next" src="images/next.png"/>
						<img class="last" src="images/last.png"/>
						<select id="pagesize" class="pagesize">
							 <option value="10" >10</option>
							 <option value="15" >15</option>
							 
						</select>
					</form>
</div>